package com.teasale.service.impl;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.teasale.vo.OrderGoodsOV;
import com.teasale.entity.SUser;
import com.teasale.service.SUserService;
import com.teasale.mapper.SUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author water003
* @description 针对表【s_user】的数据库操作Service实现
* @createDate 2023-06-06 00:52:52
*/
@Service
public class SUserServiceImpl extends ServiceImpl<SUserMapper, SUser>
    implements SUserService{
    @Autowired
    SUserMapper sUserMapper;


    @Override
    public SUser  login(String username, String password) {
        SUser sUsers = sUserMapper.selectOneByUserName(username);
        return sUsers;


    }

    @Override
    public SUser findOnde(String username) {
        return sUserMapper.selectOneByUserName(username);

    }

    @Override
    public List<OrderGoodsOV> findAllOrder(String username) {
        return sUserMapper.selectOrdersAllByUserId(username);
    }

    @Override
    public void delUser(Integer userId) {
        sUserMapper.deleteById(userId);
    }

    @Override
    public SUser addUser(SUser sUser) {
        List<SUser> sUsers = sUserMapper.selectList(Wrappers.lambdaQuery(SUser.class).eq(SUser::getUserName, sUser.getUserName()));
        if(sUsers.size() == 0){
            sUserMapper.insert(sUser);
        }else{
            sUser.setUserId(-1);//用户存在
            sUser.setUserPassword(null);
        }
        return sUser;
    }

}




